package com.zlm.tools.util;

import cn.hutool.core.util.XmlUtil;
import cn.hutool.http.webservice.SoapClient;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeaderElement;
import java.util.Map;

/**
 * @author zlm
 * @date 2023/9/18
 */
public class WebServiceUtil {

    public static void main(String[] args) throws SOAPException {
        sendWebservice();
    }

    private static void sendWebservice() throws SOAPException {
        //请求webservice地址
        String url = "http://localhost:8080/sys/webservice/kmRelativeWs?wsdl";

        QName qname = new QName("http://sys.webservice.client/","RequestSOAPHeader");
        SoapClient soapClient = SoapClient.create(url)
                //调用方法 inBlacklist
                .setMethod("tns:inBlacklist","http://webservice.relative.km.kmss.landray.com/")
                // 参数
                .setParam("cerNum","123234",false);
        SOAPHeaderElement soapHeaderElement = soapClient.addSOAPHeader(qname);
        SOAPElement user = soapHeaderElement.addChildElement("user");
        //账号
        user.setTextContent("oa");
        SOAPElement password = soapHeaderElement.addChildElement("password");
        //密码(md5)
        password.setTextContent("bdcf5fc18e1990300ed0d0a306428");

        String result = soapClient.send(true);
        System.out.println(result);
        Document document = XmlUtil.parseXml(result);
        NodeList aReturn = document.getElementsByTagName("return");
        for (int i = 0; i < aReturn.getLength(); i++) {
            Node node = aReturn.item(i);
            Map<String, Object> map = XmlUtil.xmlToMap(node);
            System.out.println(map);
        }
    }
}
